import {contextBridge, ipcRenderer} from "electron";

export function setApi(api = {}) {

  api.addLog = (log) => {
    ipcRenderer.send("addLog", log);
  }
  if (process.contextIsolated) {
    try {
      // contextBridge.exposeInMainWorld('electron', electronAPI)
      contextBridge.exposeInMainWorld("api", api);
    } catch (error) {
      console.error(error);
    }
  } else {
    // @ts-ignore (define in dts)
    window.api = api;
  }
}